import java.awt.*;
import java.lang.*;
import java.util.Scanner;
import java.util.*;
public class PhanSo implements Comparable<PhanSo>
{               
        
        PhanSo t;
        int TS;
        int MS;
        public void setTS(int k)
        {
                TS=k;
        }
        
        public int getTS()
        {
                return TS;
        }
        public void setMS(int k)
        {
                MS=k;
        }
        public int getMS()
        {
                return MS;
        }
        public void hienthi()
        {
                System.out.println(TS+"/"+MS);
        }
        public PhanSo()
        {
                
        }
        public PhanSo(int ts,int ms)
        {
                TS=ts;
                MS=ms;
        }
        int ucln(int a,int b)
        {
                while(a*b!=0)
                {
                        if(a>=b)
                        {
                                a=a-b;
                        }
                        else
                        {
                                b=b-a;
                        }
                }
                if(a>0)
                return a;
                else return a+b;
        }
        int bcnn(int a,int b)
        {
                int c=ucln(a,b);
                return (a*b)/c;
        }
        void toigian()
        {
                int d=ucln(TS,MS);
                TS=TS/d;
                MS=MS/d;
        }
        public void nghichdao()
        {
                int d=TS;
                TS=MS;
                MS=d;
        }
        public void cong(PhanSo x)
        {
                
                int d=bcnn(MS,x.getMS());
                this.setTS(d*TS/MS+d*x.getTS()/x.getMS());
                this.setMS(d);
                toigian();
                System.out.println(TS+"/"+MS); 
        }
        public void tru(PhanSo x)
        {
                
                int d=bcnn(MS,x.getMS());
                this.setTS(d*TS/MS-d*x.getTS()/x.getMS());
                this.setMS(d);
                toigian();
                System.out.println(TS+"/"+MS); 
        }
        public void nhan(PhanSo x)
        {
                
        
                this.setTS(TS*x.getTS());
                this.setMS(MS*x.getMS());
                toigian();
                System.out.println(TS+"/"+MS); 
        }
        public void chia(PhanSo x)
        {
                
                nghichdao();
                this.setTS(TS*x.getTS());
                this.setMS(MS*x.getMS());
                toigian();
                System.out.println(TS+"/"+MS); 
        }
        @Override
        public int compareTo(PhanSo o) {
                
                if(this.getMS()==o.getMS())
                        {
                        if(this.getTS()>o.getTS())
                                return 1;
                        else 
                        if(this.getTS()==o.getTS())
                                return 0;
                        else return -1;
                        }
                else 
                {
                        int d=bcnn(this.getMS(),o.getMS());
                        if(this.getTS()*d/this.getMS()>o.getTS()*d/o.getMS())
                                return 1;
                        else 
                                if(this.getTS()==o.getTS())
                                return 0;
                                else return -1;
                        
                }
        }
        public void nhap()
        {       
                Scanner scan1=new Scanner(System.in);
                System.out.println("Moi ban nhap tu so ");
                int a2=scan1.nextInt();
                System.out.println("Moi ban nhap mau so ");
                int b2=scan1.nextInt();
                setTS(a2);
                setMS(b2);
        
        }
                
                
        public static void main(String[] args)
        {
                
                
                Scanner scan=new Scanner(System.in);
                
                PhanSo ps1=new PhanSo();
                PhanSo ps2=new PhanSo();
                int a,b;
                System.out.println("Moi ban nhap tu so phan so thu nhat");
                a=scan.nextInt();
                System.out.println("Moi ban nhap mau so phan so thu nhat");
                b=scan.nextInt();
                ps1.setTS(a);
                ps1.setMS(b);
                System.out.println("Phan so cua ban la ");
                ps1.hienthi();
                int a1,b1;
                System.out.println("Moi ban nhap tu so phan so thu nhat");
                a1=scan.nextInt();
                System.out.println("Moi ban nhap mau so phan so thu nhat");
                b1=scan.nextInt();
                ps2.setTS(a1);
                ps2.setMS(b1);
                System.out.println("Phan so cua ban la ");
                ps2.hienthi();
                System.out.println("Phan so nghich dao cua phan so thu nhat la ");
                ps1.nghichdao();
                ps1.hienthi();
                ps1.nghichdao();
                System.out.println("Phan so nghich dao cua phan so thu hai la ");
                ps2.nghichdao();
                ps2.hienthi();
                ps2.nghichdao();
                System.out.println("phan so 1 cong phan so 2 la");
                //ket qua luu vao ps1 nen ps1 sau khi cong thi co gia tri bang tong 2 phan so
                ps1.cong(ps2);
                System.out.println("Gia tri 2 phan so sau khi thuc hien phep cong la");
                ps1.hienthi();
                ps2.hienthi();
                System.out.println("phan so 1 tru phan so 2 la");
                //ket qua luu vao ps1 nen ps1 sau khi thuc hien phep tinh
                ps1.tru(ps2);
                System.out.println("Gia tri 2 phan so sau khi thuc hien phep tru la");
                ps1.hienthi();
                ps2.hienthi();
                System.out.println("phan so 1 nhan phan so 2 la");
                //ket qua luu vao ps1 nen ps1 sau khi thuc hien phep tinh
                ps1.nhan(ps2);
                System.out.println("Gia tri 2 phan so sau khi thuc hien phep nhan la");
                ps1.hienthi();
                ps2.hienthi();
                System.out.println("phan so 1 chia phan so 2 la");
                //ket qua luu vao ps1 nen ps1 sau khi thuc hien phep tinh
                ps1.chia(ps2);
                System.out.println("Gia tri 2 phan so sau khi thuc hien phep chia la");
                ps1.hienthi();
                ps2.hienthi();
                System.out.println("Moi ban nhap 1 day cac phan so");
                PhanSo[] arr=new PhanSo[3];
                for(int i=0;i<3;i++)
                {
                        arr[i]=new PhanSo();
                        arr[i].nhap();
                        
                }
                System.out.println("Cac phan so khi chua sap xep la :");
                for(int i=0;i<3;i++)
                {
                        arr[i].hienthi();
                }
                
                java.util.Arrays.sort(arr);
                System.out.println("cac phan so sau khi dc sap xep la");
                for(int i=0;i<3;i++)
                {
                        arr[i].hienthi();
                }
        }
}